package com.liwei.lwmail.order.vo;


import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {

    @Getter@Setter
    private List<MemberAddressVo> addresses;

    /**
     * 所有选中的购物项
     */
    @Getter@Setter
    private List<OrderItemVo> items;
    /**
     * 积分
     */
    @Getter@Setter
    private Integer integration;
    /**
     *订单总额
     */
    private BigDecimal total;

    /**
     * 总件数
     */
    private Integer count;

    /**
     * 库存
     */
    @Getter@Setter
    private Map<Long, Boolean> hasStock;

    public Integer getCount() {
        Integer i = 0;
        if (items != null){
            for (OrderItemVo item : items) {
                 i += item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount() + ""));
                total = total.add(multiply);
            }
        }
        return total;
    }

    /**
     *应付总额
     */
    private BigDecimal pay;

    public BigDecimal getPay() {
        return getTotal();
    }

    /**
     * 防重令牌
     */
    @Getter@Setter
    private String orderToken;
}
